//package com.kaili.config;
//
//import com.kaili.common.ResponseBean;
//import com.kaili.common.exception.BaseExcept;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.servlet.http.HttpServletRequest;
//
//@ControllerAdvice
//public class ExceptionConfig {
//    private Logger logger = LoggerFactory.getLogger(getClass());
//
//    @ResponseBody
//    @ExceptionHandler(value = Exception.class)
//    public Object defaultErrorHandler(HttpServletRequest req, Exception e)  {
//        ResponseBean responseBean = new ResponseBean();
//        StackTraceElement[] traceElements = e.getStackTrace();
//
//        logger.error("报错",e);
//        e.printStackTrace();
//        if(e instanceof BaseExcept){
//            BaseExcept except = (BaseExcept) e;
//            responseBean.setStatus(except.getResponseStatus().getCode());
//            responseBean.setMessage(except.getResponseStatus().getMsg());
//
//        }else {
//            responseBean.setStatus(-400);
//            responseBean.setMessage("异常类:" + e.getClass().getName() + "内容消息:" + e.getMessage());
//        }
//        /*StringWriter stringWriter = new StringWriter();
//        e.printStackTrace(new PrintWriter(stringWriter));
//        responseBean.setData(stringWriter.toString());*/
//        if(traceElements.length>0){
//            responseBean.setData(traceElements[0].toString());
//        }
//        return responseBean;
//
//    }
//}
